﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for cls_LOP_HOCCAPLOP
/// </summary>
public class cls_LOP_HOCCAPLOP
{
	public cls_LOP_HOCCAPLOP()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    #region Select Lớp học
    public DataTable Select()
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        try
        {
            dt = connect.GetSelectCommand("LOP_HOCCAPLOP_Select", null);
        }
        catch
        {
            dt = null;
        }
        return dt;
    }
    public DataTable getByMaCN(string F_MACN)
    {
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MACN", F_MACN);
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        try
        {
            dt = connect.GetSelectCommand("LOP_HOCCAPLOP_GetByMaCN", para);
        }
        catch
        {
            dt = null;
        }
        return dt;
    }
    
    #endregion

    #region Insert Lớp học
    public string Insert(string malop, DateTime ngaykhaigiang, string thoikhoabieu, string mach, int thangthu, string tgthuphi, string macn, int F_STTCAPLOP, string F_MAGV, DateTime F_NGAYBD, DateTime F_NGAYKT, string F_PHONGHOC, int F_STATUSLOCK_LOP)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[13];
        para[0] = new SqlParameter("@malop", malop);
        para[1] = new SqlParameter("@ngaykg", ngaykhaigiang);
        para[2] = new SqlParameter("@tghoc", thoikhoabieu);
        para[3] = new SqlParameter("@mach", mach);
        para[4] = new SqlParameter("@thangthu", thangthu);
        para[5] = new SqlParameter("@tgthuphi", tgthuphi);
        para[6] = new SqlParameter("@macn", macn);

        para[7] = new SqlParameter("@F_STTCAPLOP", F_STTCAPLOP);
        para[8] = new SqlParameter("@F_MAGV", F_MAGV);
        para[9] = new SqlParameter("@F_NGAYBD", F_NGAYBD);
        para[10] = new SqlParameter("@F_NGAYKT", F_NGAYKT);
        para[11] = new SqlParameter("@F_PHONGHOC", F_PHONGHOC);
        para[12] = new SqlParameter("@F_STATUSLOCK_LOP", F_STATUSLOCK_LOP);
        

        try
        {
            connect.ExecuteQuery("LOP_HOCCAPLOP_Insert", para);
            return "OK";
        }
        catch(Exception ex)
        {
            return ex.Message;
            //return "ERR"; 
        }
    }
    #endregion

    #region Update Lớp học
    public string Update(string malop, DateTime ngaykhaigiang, string thoikhoabieu, bool ketthuc, string mach, int thangthu, string tgthuphi, string macn, int F_STTCAPLOP, string F_MAGV, DateTime F_NGAYBD, DateTime F_NGAYKT, string F_PHONGHOC, int F_STATUSLOCK_LOP)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[14];
        para[0] = new SqlParameter("@malop", malop);
        para[1] = new SqlParameter("@ngaykg", ngaykhaigiang);
        para[2] = new SqlParameter("@tghoc", thoikhoabieu);
        para[3] = new SqlParameter("@kt", ketthuc);
        para[4] = new SqlParameter("@mach", mach);
        para[5] = new SqlParameter("@thangthu", thangthu);
        para[6] = new SqlParameter("@tgthuphi", tgthuphi);
        para[7] = new SqlParameter("@macn", macn);

        para[8] = new SqlParameter("@F_STTCAPLOP", F_STTCAPLOP);
        para[9] = new SqlParameter("@F_MAGV", F_MAGV);
        para[10] = new SqlParameter("@F_NGAYBD", F_NGAYBD);
        para[11] = new SqlParameter("@F_NGAYKT", F_NGAYKT);
        para[12] = new SqlParameter("@F_PHONGHOC", F_PHONGHOC);
        para[13] = new SqlParameter("@F_STATUSLOCK_LOP", F_STATUSLOCK_LOP);


        try
        {
            connect.ExecuteQuery("LOP_HOCCAPLOP_Update", para);
            return "OK";
        }
        catch
        { return "ERR"; }
    }
    public string Update_change_key(string malop, string malopmoi, DateTime ngaykhaigiang, string thoikhoabieu, bool ketthuc, string mach, int thangthu, string tgthuphi, string macn, int F_STTCAPLOP, string F_MAGV, DateTime F_NGAYBD, DateTime F_NGAYKT, string F_PHONGHOC, int F_STATUSLOCK_LOP)
    {
        DatabaseConnect connect = new DatabaseConnect();

        SqlParameter[] para = new SqlParameter[15];
        para[0] = new SqlParameter("@malop", malop);
        para[1] = new SqlParameter("@ngaykg", ngaykhaigiang);
        para[2] = new SqlParameter("@tghoc", thoikhoabieu);
        para[3] = new SqlParameter("@kt", ketthuc);
        para[4] = new SqlParameter("@mach", mach);
        para[5] = new SqlParameter("@thangthu", thangthu);
        para[6] = new SqlParameter("@tgthuphi", tgthuphi);
        para[7] = new SqlParameter("@macn", macn);

        para[8] = new SqlParameter("@F_STTCAPLOP", F_STTCAPLOP);
        para[9] = new SqlParameter("@F_MAGV", F_MAGV);
        para[10] = new SqlParameter("@F_NGAYBD", F_NGAYBD);
        para[11] = new SqlParameter("@F_NGAYKT", F_NGAYKT);
        para[12] = new SqlParameter("@F_PHONGHOC", F_PHONGHOC);
        para[13] = new SqlParameter("@malopmoi", malopmoi);
        para[14] = new SqlParameter("@F_STATUSLOCK_LOP", F_STATUSLOCK_LOP);

        try
        {
            connect.ExecuteQuery("LOP_HOCCAPLOP_Update_change_key", para);
            return "OK";
        }
        catch
        { return "ERR"; }
    }
    #endregion

    #region Delete Lớp học
    public string Delete(string malop)
    {
        DatabaseConnect connect = new DatabaseConnect();

        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@malop", malop);

        try
        {
            connect.ExecuteQuery("LOP_HOCCAPLOP_Delete", para);
            return "OK";
        }
        catch { return "ERR"; }
    }
    #endregion

    public DataTable CAPLOPgetByMaCH(string F_MACH)
    {
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MACH", F_MACH);
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        try
        {
            dt = connect.GetSelectCommand("LOP_HOCCAPLOP_CAPLOPGetByCH", para);
        }
        catch
        {
            dt = null;
        }
        return dt;
    }
}